package com.team.easybuy.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import java.util.Properties;

import javax.annotation.Resource;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class EmailUtil {

    public static boolean sendEmail(String code,String emailReceiver,JavaMailSender javaMailSender) {
        SimpleMailMessage message = new SimpleMailMessage();
        // 设置邮件发送者
        message.setFrom("2651470635@qq.com");
        // 设置邮件接收者
        message.setTo(emailReceiver);
        // 设置邮件的主题
        message.setSubject("【易卖网】验证码");
        // 设置邮件的正文

        String text = "您正在进行密码找回，您的验证码为：" + code + ",5分钟内有效,请勿泄露给他人。";
        message.setText(text);
        // 发送邮件
        try {
            javaMailSender.send(message);
            return true;
        } catch (MailException e) {
            e.printStackTrace();
        }
        return false;

    }

}
